import time
import datetime as dt

class tradetime_helper(object):
    def __init__(self):
        self.day_start_time = dt.time(8, 55)
        self.day_end_time = dt.time(15, 5)

        self.night_start_time = dt.time(20,55)
        self.night_end_time = dt.time(23,5)

    # 目前只排除掉了周末
    def is_trade_day(self, now:dt.date = None):
        if now is None:
            now = dt.date.today()

        week = now.isoweekday()

        if week < 6:
            return True
        else:
            return False



    # 排除掉中间休息时间
    def is_trade_time(self, tm:dt.time= None):
       if tm is None:
            now = dt.datetime.now()
            tm = now.time()

        

    # 是否交易时间， 中间休息也算的
    def is_trade_life_time(self, tm:dt.time= None):
        if tm is None:
            now = dt.datetime.now()
            tm = now.time()

        return self.is_day_life_time(tm) or self.is_night_life_time(tm)


    def is_day_life_time(self, tm:time = None):
        
        if tm is None:
            now = dt.datetime.now()
            tm = now.time()
        #hr = tm.hour

        if tm > self.day_start_time and tm < self.day_end_time:
            return True
        else:
            return False


    def is_night_life_time(self, tm:time= None):

        if tm is None:
            now = dt.datetime.now()
            tm = now.time()

        if tm > self.night_start_time and tm < self.night_end_time:
            return True
        else:
            return False





if __name__ == '__main__':
    th = tradetime_helper()
    # now = date.today()
    
    # week = now.isoweekday()
    # now = datetime.now()

    # print(now.date())
    # print(now.time())
    tm = dt.time(8,56)

    day1 = dt.date(2023, 8, 12)
    # print(th.is_day_life_time(tm))
    print(th.is_trade_day(day1))

    print(th.is_night_life_time())
    print(th.is_day_life_time())
    


